#coding: utf-8

import random

from cocos2d import *
import Singleton

from NetworkHelper  import NetClient

DEFAULT_TRANSITIONS = [
CCTransitionRotoZoom,
CCTransitionJumpZoom,
CCTransitionMoveInL,
CCTransitionMoveInR,
CCTransitionMoveInT,
CCTransitionMoveInB,
CCTransitionSlideInL,
CCTransitionSlideInR,
CCTransitionSlideInT,
CCTransitionSlideInB,
CCTransitionShrinkGrow,
CCTransitionFlipX,
CCTransitionFlipY,
CCTransitionFlipAngular,
CCTransitionZoomFlipX,
CCTransitionZoomFlipY,
CCTransitionZoomFlipAngular,
CCTransitionCrossFade,
CCTransitionTurnOffTiles,
CCTransitionSplitCols,
CCTransitionSplitRows,
CCTransitionCrossFade,
CCTransitionFadeTR,
CCTransitionFadeBL,
CCTransitionFadeUp,
CCTransitionFadeDown,
CCTransitionPageTurn,
CCTransitionProgressRadialCCW,
CCTransitionProgressRadialCW,
CCTransitionProgressHorizontal,
CCTransitionProgressVertical,
CCTransitionProgressInOut,
CCTransitionProgressOutIn,
]

class SceneTransition(Singleton.Singleton):
    def __init__(self):
        pass

    @staticmethod
    def getInstance():
        return Singleton.getInstance(SceneTransition)

    def defaultTransition(self, scene, real_scene = None):
        if real_scene:
            NetClient.switch_scene(real_scene)
        else:
            NetClient.switch_scene(scene)

        if sharedDirector.getRunningScene():
            sharedDirector.replaceScene(scene)
        else:
            sharedDirector.runWithScene(scene)

    def specTransition(self, ts, dt, scene):
        if ts == CCTransitionPageTurn:
            self.defaultTransition(ts(dt, scene, False), scene)
        else:
            self.defaultTransition(ts(dt, scene), scene)

    def randomTransition(self, dt, scene):
        trans_tp = random.choice(random.sample(DEFAULT_TRANSITIONS, 3))
        if trans_tp == CCTransitionPageTurn:
            self.defaultTransition(trans_tp(dt, scene, False), scene)
        else:
            self.defaultTransition(trans_tp(dt, scene), scene)
